package ModelLayer;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import DBLayer.GetMax;

public class SalesOrder {

	
	private int saleID;
	private String date;
	private double tAmount;
	private String status;
	private String deliveryDate;
	private Customer customer;
	private Invoice invoice;
	private ArrayList<OrderLine> orderLines;
	
	public SalesOrder(int saleID){
		this.saleID=saleID;
		orderLines=new ArrayList<OrderLine>();
		tAmount=0;
		date=getDateTime();
	}
	
	
	public SalesOrder() {
		// TODO Auto-generated constructor stub
		orderLines=new ArrayList<OrderLine>();
		saleID=GetMax.getMaxId("Select max(Sale_ID) from SalesOrder")+1;
		tAmount=0;
		date=getDateTime();
		
	}




	public SalesOrder(int saleID, String date, double tAmount, String status,
			String deliveryDate, Customer customer, Invoice invoice) {
	
		this.saleID = saleID;
		this.date = date;
		this.tAmount = tAmount;
		this.status = status;
		this.deliveryDate = deliveryDate;
		this.customer = customer;
		this.invoice = invoice;
		orderLines=new ArrayList<OrderLine>();
	}





	
	
	
	public int getSaleID() {
		return saleID;
	}
	public void setSaleID(int saleID) {
		this.saleID = saleID;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public double gettAmount() {
		return tAmount;
	}
	public void settAmount(double tAmount) {
		this.tAmount = tAmount;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getDeliveryDate() {
		return deliveryDate;
	}
	public void setDeliveryDate(String deliveryDate) {
		this.deliveryDate = deliveryDate;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public ArrayList<OrderLine> getOrderLines() {
		return orderLines;
	}
	public void setOrderLines(ArrayList<OrderLine> orderLines) {
		this.orderLines = orderLines;
	}


	public Invoice getInvoice() {
		return invoice;
	}


	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}


	public void addOrderLine(OrderLine orderLine) {
		orderLines.add(orderLine);
		
	}
	
	
	public double getAmountAfterTaxes()
	{
		calculateTotalAmount();
		
		return tAmount*1.25;
		
		
	}


	private void calculateTotalAmount() {
		
		for(OrderLine line :orderLines)
			tAmount += (line.getQuantity()+line.getProduct().getsPrice());
		
	}
	
    private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
        Date date = new Date();
        return dateFormat.format(date);
    }
	
	
	
}//end clas
